<?php
/**
 * Description of class
 *
 * @author ������
 */
abstract class LoginStrategy {

    abstract function doLogin(LRuser $user);
    
    protected function generateCode($length = 6) {
        $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPRQSTUVWXYZ0123456789";
        $code = "";
        $clen = strlen($chars) - 1;
        while (strlen($code) < $length) {
            $code .= $chars[mt_rand(0, $clen)];
        }

        return $code;
    }

    protected function _makeLogin(LRuser $user, $data) {
   

        
        $hash = md5(self::generateCode(10));
        
        $insip = "";
        if (!@$_POST['not_attach_ip']) {//���� ����������� ������ �������� � IP
            //��� ����������� ������ � �����
            $insip = ", user_ip=INET_ATON('" . $_SERVER['REMOTE_ADDR'] . "')";
        }
        // ���������� � �� ����� ��� ����������� � IP
        $user->LRModel->updateUserHashAndIP($hash, $insip, $data['user_id']);
        //������������� ���� � �����
        setcookie("user_id", $data['user_id'], time() + 60 * 60 * 24 * 30, "/");
        setcookie("hash", $hash, time() + 60 * 60 * 24 * 30, "/");

                $user->isLogged = true;
                $user->user_id = $data['user_id'];
                $user->user_login = $data['user_login'];
                $user->user_hash = $data['user_hash'];
                $user->user_ip = $data['user_ip'];
                $user->realname = $data['realname'];
                $user->phone = $data['phone'];
                $user->mail = $data['mail'];
                $user->bday = $data['bday'];
                $user->photo_small = $data['photo_small'];
                $user->photo_medium = $data['photo_medium'];
                $user->photo_big = $data['photo_big'];
                $user->ownerof = $data['ownerof'];
                $user->user_id = $data['user_id'];
                $user->user_hash = $hash;
    }

}
?>
